<template>
	<view>
		<view class="section">
			<view class="cl-tabs">
				<view class="item" @click="tabChange(index)" :class="tabIndex == index ? 'active' : ''"
					v-for="(item,index) in tabList">
					{{item.title}}
				</view>
			</view>
		</view>
		<view class="section">
			<view class="report-list">
				<view class="item" v-for="(item,index) in list">
					<view class="top">
						<view class="label" v-if="item.level">{{item.level}}</view>
						{{item.labels}}
						<view class="status">{{item.status_text}}</view>
					</view>
					<view class="address">
						<u-icon name="map-fill"></u-icon> {{item.address}}
					</view>
					<view class="images" v-if="item.images">
						<u-image @click.native.stop="previewImage(index,i)" v-for="(img,i) in item.images_array"
							mode="aspectFill" :src="img" width="190" height="190"></u-image>
					</view>
					<view class="content">{{item.content}}</view>
					<view class="bottom">
						<view class="time">{{item.createtime_text}}</view>
						<u-button type="default" shape="circle" size="mini" @click="navTo('/pages/user/report/show',{id:item.id})" :plain="true"
							class="oper-btn">查看</u-button>
					</view>
				</view>
			</view>
		</view>
		<!-- 空数据 -->
		<view class="u-u-p-t-80 u-m-t-80 u-p-b-80" v-if="!list.length">
			<u-empty src="/static/empty-log.png" text="什么也没有~" icon-size="375" mode="list"></u-empty>
		</view>
		<!-- 加载更多 -->
		<view class="u-p-b-30" v-if="list.length">
			<u-loadmore :status="has_more ? status : 'nomore'" />
		</view>
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					type: 0,
					title: '审核中'
				}, {
					type: 1,
					title: '已处理'
				}],
				tabIndex: 0,
				list: [],
				page: 1,
				is_update: false,
				has_more: false,
				scrollTop: 0,
				status: 'loadmore',
			}
		},
		onLoad() {
			this.getMyReportList();
		},
		methods: {
			previewImage: function(index, i) {
				uni.previewImage({
					urls: this.list[index].images_array,
					current: i
				});
			},
			tabChange: function(index) {
				this.tabIndex = index;
				this.is_update = true;
				this.page = 1;

				this.getMyReportList();
			},
			getMyReportList: async function() {
				this.$u.api.getReportMyList({
					page: this.page,
					type: this.tabList[this.tabIndex].type
				}).then(res => {
					uni.stopPullDownRefresh();
					if (res.code) {
						if (this.is_update) {
							this.list = [];
							this.is_update = false;
						}
						this.list = [...this.list, ...res.data.data];
						this.has_more = res.data.current_page < res.data.last_page;
					}
				});
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		//下拉刷新
		onPullDownRefresh() {
			this.is_update = true;
			this.page = 1;
			this.getMyReportList();
		},
		onReachBottom() {
			if (this.has_more) {
				this.status = 'loading';
				this.page++;
				this.getMyReportList();
			}
		}
	}
</script>

<style>
	page {
		background-color: #f4f4f4;
	}

	.section {
		padding: 50rpx 50rpx 0 50rpx;
	}
</style>
